<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/9 0009
 * Time: 14:23
 */

namespace logic\yuding\driver;
use logic\LogicException;
use logic\yuding\Factory;

class HotelTravel
{
	//支付信息集合
	public $payDataResult = array();
	//用户订单详细信息集合
	public $viewDataResult = array();

	public function mobile($data,$hotelData){
		//验证travel订单
		$travelFactory = Factory::main('Travel');
		$order1 = $travelFactory->payTicket( $data[1] , $this->userInfo );
		$travelFactory->clear();
		$order2 = $travelFactory->payTicket( $data[2] , $this->userInfo );
		$order = array($order1,$order2);

		//验证酒店订单
		$hotelFactory = Factory::main('Hotel');
		$hotelFactory -> setData($hotelData);
		$hotelFactory -> setMsg();

		//构建前台用户订单信息显示数据
		$da = array();
		$da['username']     =   $order1['data']['username'];
		$da['idcard']       =   $order1['data']['shenfenid'];
		$da['username1']    =   $order2['data']['username'];
		$da['idcard1']      =   $order2['data']['shenfenid'];
		$da['phone']        =   $order1['data']['phone'];
		$da['yudingdate']   =   $order1['data']['date_str'];
		$da['addtime']      =   date('Y-m-d H:i:s');
		$da['productId']    =   $hotelData['room_id'];
		$da['discount_vouchers']= $hotelFactory->data['discount_vouchers'];
		$da['moneys']       =   $hotelFactory->data['moneys'];
		$da['uid']          =   $this->userInfo['uid'];
		$da['open_id']      =   $this->userInfo['open_id'];
		$this->viewDataResult = $da;
		//构建订单数据处理格式化
		$order_datas=array();
		if(db('order')->insert($da)){
			$orderData['orderId']=db('order')->InsertGetId();
			//订单数据封装
			$order_datas['order_id']=$orderData['orderId'];
			$order_datas['data']=serialize($order);
			$order_datas['addtime']=date('Y-m-d H:i:s');
			db('order_data')->insert($order_datas);
		}else{
			throw new LogicException('下单失败,请关闭页面重试');
		}

		//微信订单封装
		$orderData = array();
		$orderData['Detail']    =   $hotelFactory->roomResult['title'];
		$orderData['Body']      =   $hotelFactory->roomResult['title'];
		$orderData['Attach']    =   "HOTEL";
		$orderData['Total_fee'] =   $hotelFactory->roomResult*100;
		$orderData['Goods_tag'] =   $hotelFactory->roomResult['title'];
		$this->payDataResult = $orderData;

	}



}